import React, { Component } from 'react'
import store from '../store'


// redux-thunk异步
export default class Brother2 extends Component {
  constructor () {
    super()

    this.state = {
      num: store.getState().count,
      name: store.getState().user
    }
  }

  componentDidMount () {
    // 手动订阅更新，构造器只执行一次，需要监视值改变
    // react-redux 优化React组件，减少对store的依赖 可以自动监视更新
    store.subscribe(() => {
      // console.log(store.getState())
      this.setState({
        num: store.getState().count,
        name: store.getState().user
      })
    });
  }


  render() {
    return (
      <div>
        Brother2
        <br/>
        <br/>
        <br/>
        仓库中最新的值---{this.state.num}---{this.state.name}
      </div>
    )
  }
}
